<%= render partial: 'spree/admin/shared/order_tabs', locals: { current: :customer_returns } %>

<% content_for :page_actions do %>
  <% if @order.shipments.any?(&:shipped?) && can?(:create, Spree::CustomerReturn) %>
    <%= button_link_to Spree.t(:new_customer_return), spree.new_admin_order_customer_return_path(@order), icon: 'add', class: 'btn-success' %>
  <% end %>
<% end %>

<% content_for :page_title do %>
  / <%= plural_resource_name(Spree::CustomerReturn) %>
<% end %>

<% if @order.shipments.any?(&:shipped?) %>

  <% if @customer_returns.any? %>
    <table class="table">
      <thead data-hook="customer_return_header">
        <tr>
          <th><%= Spree.t(:return_number) %></th>
          <th><%= Spree.t(:pre_tax_total) %></th>
          <th><%= "#{Spree.t('date')}/#{Spree.t('time')}" %></th>
          <th><%= Spree.t(:reimbursement_status) %></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <% @customer_returns.each do |customer_return| %>
          <tr id="<%= spree_dom_id(customer_return) %>" data-hook="customer_return_row">
            <td><%= link_to customer_return.number, edit_admin_order_customer_return_path(@order, customer_return) %></td>
            <td><%= customer_return.display_pre_tax_total.to_html %></td>
            <td><%= pretty_time(customer_return.created_at) %></td>
            <td>
              <% if customer_return.fully_reimbursed? %>
                <span class="label label-success"><%= Spree.t(:reimbursed) %></span>
              <% else %>
                <span class="label label-info"><%= Spree.t(:incomplete) %></span>
              <% end %>
            </td>
            <td class='actions actions-1' data-hook="admin_orders_customer_returns_index_row_actions">
              <%= link_to_edit_url(edit_admin_order_customer_return_path(@order, customer_return), title: "admin_edit_#{dom_id(customer_return)}", no_text: true) if can?(:edit, customer_return) %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  <% else %>
    <div class="alert alert-info no-objects-found">
      <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::CustomerReturn)) %>,
      <%= link_to(Spree.t(:add_one), spree.new_admin_order_customer_return_path(@order)) if can?(:create, Spree::CustomerReturn) %>!
    </div>
  <% end %>
<% else %>
  <div data-hook="customer_return_cannot_create" class="alert alert-info no-objects-found">
    <%= Spree.t(:cannot_create_customer_returns) %>
  </div>
<% end %>
